/**
 * @(#) GraphDot��2008-7-13
 * Copyright 2008 Program Analysis Research Group(PARG),Institute of Software, Peking University.
 * All rights reserved.
 */
package graphclustering;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

import graphclustering.data.DWGraph;
import graphclustering.data.LoadandSave;

/**
 * @author HeLi
 */
public class GraphDot {
    public static void main(String[] args) throws Exception {
        DWGraph graph = LoadandSave.loadGraphFromFile(args[0]);
        PrintWriter writer = new PrintWriter(new FileWriter(new File(args[1])));
        writer.println("digraph {");
        for (int i = 0; i < graph.graph.length; i++) {
            for (int j = 0; j < graph.graph[i].length; j++) {
                if (graph.graph[i][j] > 0.0f) {
                    writer.println(graph.nodeIDList.get(i) + "->"
                            + graph.nodeIDList.get(j) + ";");
                }
            }
        }
        for (int i = 0; i < graph.graph.length; i++) {
            float weightSum = 0.0f;
            for (int j = 0; j < graph.graph[i].length; j++) {
                weightSum += graph.graph[i][j] + graph.graph[j][i];
            }
            if (weightSum == 0.0) {
                writer.println(graph.nodeIDList.get(i) + ";");
            }
        }
        writer.println("}");
        writer.close();
    }
}
